﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MVCPets.Extensions;

namespace MVCPets.Tests.Extensions
{
  [TestClass]
  public class PrimaitiveExtensions
  {
    private struct testStruct { string s; };

    [TestMethod]
    public void Can_Get_Nullable()
    {
      int i = 120;
      Nullable<int> item = i.AsNullable();
      Assert.IsTrue(item.HasValue);
      Assert.IsTrue(item.Value == i);
    }

    [TestMethod]
    public void Compare_String_Ignore_Case_Returns_True()
    {
      var guid = Guid.NewGuid();

      Assert.IsTrue(guid.ToString().ToLower().EqualsIgnoreCase(guid.ToString().ToUpper()));
    }

    [TestMethod]
    public void Can_Compute_Hash()
    {
      byte[] toHash = { 0, 1, 1, 0, 1 };
      byte[] hashed = toHash.ComputeHash();
      Assert.IsTrue(toHash != hashed);
    }

    [TestMethod]
    public void Can_Convert_To_Base64()
    {
      byte[] toHash = { 0, 1, 1, 0, 1 };
      byte[] hashed = toHash.ComputeHash();
      Assert.IsTrue(toHash != hashed);

      string s = hashed.ToBase64String();
      Assert.IsTrue(!string.IsNullOrEmpty(s));
    }

    [TestMethod]
    public void Can_Concat_Two_Things()
    {
      testStruct one = new testStruct();
      string two = "2";

      string result = one.Concatinate(two);
      Assert.IsTrue(result == "MVCPets.Tests.Extensions.PrimaitiveExtensions+testStruct2");
    }

    [TestMethod]
    public void Can_Concat_Three_Things()
    {
      testStruct one = new testStruct();

      string result = one.Concatinate("2", "3");
      Assert.IsTrue(result == "MVCPets.Tests.Extensions.PrimaitiveExtensions+testStruct23");
    }

    [TestMethod]
    public void Can_Concat_Many_Things()
    {
      testStruct one = new testStruct();

      string result = one.Concatinate("2", "3", "4", "5", "6");
      Assert.IsTrue(result == "MVCPets.Tests.Extensions.PrimaitiveExtensions+testStruct23456");
    }

    [TestMethod]
    public void Can_Get_String()
    {
      string data = "data";
      string result = data.GetBytes().GetString();
      Assert.IsTrue(data == result);
    }
  }
}
